<template>
	<view class="postsList" v-if="props.postData.length > 0">
		<PostItem v-for="(item, index) in props.postData" :id="item.id" :content="item.content"
			:username="item.username" :likeNum="item.likeNum" :commentNums="item.commentNums"
			:avatarUrl="item.avatarUrl" :statu="item.statu" :date="item.date" :ifMine="props.ifMine"
			:ifAudit="props.ifAudit" :key="item.id" :title='item.title' :type='item.type' :clubName="item.clubName"
			:ifTeacher="props.ifTeacher" />
		<view class="noMore">
			<!-- 			<van-icon size="50rpx" name="back-top"  @click="scrollToTop"/> -->
			{{data.length===props.total?'没有更多了~':'加载中...'}}
		</view>
	</view>
	<view class="noData" v-else>
		<view style="width: 100%; display: flex; justify-content: center">
			<image class="noDataImg" src="@/static/icons/noDataIcon.svg" mode="aspectFill"></image>
		</view>
		<view> 暂无数据 </view>
	</view>
	<ToTop />
</template>

<script setup>
	import {
		ref,
		watch
	} from "vue";
	import PostItem from "./PostItem.vue";
	import ToTop from "../../../components/ToTop.vue";
	import {
		onReachBottom
	} from "@dcloudio/uni-app";
	const props = defineProps({
		postData: {
			type: Array,
			default: [],
		},
		ifMine: {
			type: Boolean,
			default: false,
		},
		ifAudit: {
			type: Boolean,
			default: false,
		},
		ifTeacher: {
			type: Boolean,
			default: false,
		},
		page: {
			type: Number,
			default: 1
		},
		total: {
			type: Number,
			default: 0,
		},
		type: {
			type: String,
			default: ''
		},
		clubName: {
			type: String,
			default: ""
		}
	});

	const emit = defineEmits(['update:page']);
	const pageTemp = ref(1)
	const data = ref([])
	watch(() => props.postData, (newValue) => {
		data.value = newValue
	}, {
		immediate: true
	})

	const status = 1

	const scrollToTop = () => {
		uni.pageScrollTo({
			scrollTop: 0,
			duration: 300,
		});
	};
</script>

<style lang="less" scoped>
	.postsList {
		margin-top: 30rpx;
		width: 100vw;
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 20rpx;

		.noMore {
			margin-top: 20rpx;
			text-align: center;
			display: flex;
			flex-direction: column;
			gap: 10rpx;
			align-items: center;
			padding-bottom: 40rpx;
		}
	}

	.noData {
		margin-top: 100rpx;
		flex-direction: column;
		align-items: center;
		gap: 20rpx;

		image {
			height: 500rpx;
			width: 500rpx;
		}

		view {
			text-align: center;
			font-size: 45rpx;
		}
	}
</style>